<template>
    <div id="basicInformation_cpxx_add_" class="padding" >
        <el-form ref="saveDatas" :rules="rules"  :model="saveDatas" :label-position="labelPosition" label-width="80px" class="padding" >
            <el-form-item label="选择分类" prop="dlxl">
                <el-cascader
                        v-model="saveDatas.dlxl"
                        :options="options"
                        change-on-select
                        :props="props">
                </el-cascader>
            </el-form-item>
            <el-form-item label="商品编码" prop="spbm">
                <el-input v-model="saveDatas.spbm" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="商品名称" prop="spmc">
                <el-input v-model="saveDatas.spmc" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="商品产地" prop="spcd">
                <el-input v-model="saveDatas.spcd" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="供应商" prop="gys">
                <el-input v-model="saveDatas.gys" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="商品单价" prop="dj">
                <el-input v-model.number="saveDatas.dj" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="优惠价" prop="yhj">
                <el-input v-model.number="saveDatas.yhj" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="商品备注" prop="bz">
                <el-input v-model="saveDatas.bz" style="width:300px"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit('saveDatas')">保存</el-button>
                <el-button @click="resetForm('saveDatas')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        name: "index",
        props:['options','saveDatas'],
        data() {
            var checkDj = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('单价不能为空'));
                }
                if (!Number.isInteger(value)) {
                    consoleLog(Number.isInteger(value))
                    callback(new Error('请输入数字'));
                } else {
                    if (value < 0) {
                        callback(new Error('单价必须大于0'));
                    } else if (value>999999999) {
                        callback(new Error('单价必须小于10位'));
                    } else {
                        callback();
                    }
                }
            };
            var checkYhj = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('优惠价不能为空'));
                }
                if (!Number.isInteger(value)) {
                    callback(new Error('请输入数字'));
                } else {
                    if (value < 0) {
                        callback(new Error('优惠价必须大于0'));
                    } else if (value>999999999) {
                        callback(new Error('单价必须小于10位'));
                    } else {
                        callback();
                    }
                }
            };
            return {
                labelPosition:"right",
                props: {
                    value: 'id',
                    label: 'label',
                    children: 'children'
                },
                rules:{//规则
                    dlxl:[
                        { required: true, message: '请选择分类', trigger: 'change' },
                    ],
                    spbm:[
                        { required: true, message: '请输入商品编码', trigger: 'blur' }
                    ],
                    spmc:[
                        { required: true, message: '请输入商品名称', trigger: 'blur' }
                    ],
                    spcd:[
                        { required: true, message: '请输入商品产地', trigger: 'blur' }
                    ],
                    gxs:"",
                    dj:[
                        { required: true,validator: checkDj, trigger: 'blur' },
                    ],
                    yhj:[
                        { required: true,validator: checkYhj, trigger: 'blur' },
                    ],
                    bz:"",
                }
            }
        },
        methods: {
            onSubmit(saveDatas){//保存数据
                this.$refs[saveDatas].validate((valid) => {
                    if (valid) {
                        this.$message_.postTips(this,'保存','crm-product/save',{CrmMallProduct:this.saveDatas},null,()=>{
                            layer.close(allIndex)
                        })
                    } else {
                        return false;
                    }
                })
            },
            resetForm(saveDatas){//重置数据
                this.$refs[saveDatas].resetFields();
            }
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
